package com.bbva.gptf.back.transformador;

import java.util.ArrayList;
import java.util.List;
import java.math.BigDecimal;
import java.sql.ResultSet;
import java.sql.SQLException;

import org.springframework.core.convert.converter.Converter;

import com.bbva.gptf.dto.bean.InstrumentoType;
import com.bbva.gptf.dto.bean.TipoContrato;
import com.bbva.gptf.dto.bean.TipoNominal;
import com.bbva.gptf.dto.bean.TipoNivel;
import com.bbva.gptf.dto.bean.TipoOperacion;

/**
 * @author Javier Estrella
 * @version 1.0
 * @created 06-mar-2013 18:34:05
 */
public class ResultSetToInstrumentoTypeTransformador implements Converter<ResultSet,List<InstrumentoType>> {

	private static final String ID = "NU_POSICION";
	private static final String CDCONTRATO = "CD_CONTRATO";
	private static final String CDCLASIFICACION = "CD_CLASIFICACION";
	private static final String CLASIFICACION = "NB_CLASIFICACION";
	private static final String TIPOCONTRATO = "TP_CONTRATO";
	private static final String CDVALORBMV = "CD_VALOR_BMV";
	private static final String EMISORA = "NB_EMISORA";
	private static final String SERIE = "NB_SERIE";
	private static final String CATITULOS = "NU_CA_TITULOS";
	private static final String CAPRECIO = "NU_CA_PRECIO";
	private static final String CAMONTO = "NU_CA_MONTO";
	private static final String CALIQUIDEZ = "NU_CA_LIQUIDEZ";
	private static final String CAPCINTEGRACION = "PC_CA_INTEGRACION";
	private static final String CADELTAINSTRUMENTO = "NU_CA_DELTA_INSTR";
	private static final String CACONTRIBUCIONDELTA = "NU_CA_CONTRIBUCIO";
	private static final String CATASA = "NU_CA_TASA";
	private static final String CAVALUACIONCARTERA = "NU_CA_VALUACARTER";
	private static final String CABENCHPCINTEGRACION = "PC_CA_BENCH_INTEG";
	private static final String CABENCHCONTRIBUCIONDELTA = "NU_CA_BENCH_CONT";
	private static final String CADIFERENCIAPCINTEGRACION = "PC_CA_DIFBENCHINT";
	private static final String CASUBOSOBREDELTAS = "NU_CA_SUBOSOBRED";
	private static final String CFTITULOS = "NU_CF_TITULOS";
	private static final String CFPRECIO = "NU_CF_PRECIO";
	private static final String CFMONTO = "NU_CF_MONTO";
	private static final String CFLIQUIDEZ = "NU_CF_LIQUIDEZ";
	private static final String CFPCINTEGRACION = "PC_CF_INTEGRACION";
	private static final String CFDELTAINSTRUMENTO = "NU_CF_DELTA_INSTR";
	private static final String CFCONTRIBUCIONDELTA = "NU_CF_CONTRIBUCIO";
	private static final String CFTASA = "NU_CF_TASA";
	private static final String CFVALUACIONCARTERA = "NU_CF_VALUACARTER";
	private static final String CFBENCHPCINTEGRACION = "PC_CF_BENCH_INTEG";
	private static final String CFBENCHCONTRIBUCIONDELTA = "NU_CF_BENCH_CONT";
	private static final String CFDIFERENCIAPCINTEGRACION = "PC_CF_DIFBENCHINT";
	private static final String CFSUBOSOBREDELTAS = "NU_CF_SUBOSOBRED";
	private static final String MONTOOPERAR = "NU_MONTO_OPERAR";
	private static final String PCINTEGRACIONOBJETIVO = "PC_INTEG_OBJETIVO";
	private static final String PCDIFINTEGRACIONOBJETIVO = "PC_DIF_INTE_OBJET";
	private static final String VALORNOMINAL = "NU_VALOR_NOMINAL";
	private static final String TIPONOMINAL = "TP_NOMINAL";
	private static final String IMPACTOMONTO = "NU_IMPACT_MONTO";
	private static final String IMPACTOTITULOS = "NU_IMPACT_TITULOS";
	private static final String IMPACTOMONTOFIDEICOMISOS = "NU_IMPACT_FIDEICO";
	private static final String IMPACTOMONTOPATRIMONIAL = "NU_IMPACT_PATRIM";
	private static final String IMPACTOMONTOTOTAL = "TO_IMPACT_MONTO";
	private static final String TIPONIVEL = "TP_NIVEL";
	private static final String TIPOOPERACION = "TP_OPERACION";
	private static final String EFECTIVOHOY = "IM_EFECT_HOY";
	private static final String EFECTIVO24 = "IM_EFECT_24";
	private static final String EFECTIVO48 = "IM_EFECT_48";
	private static final String EFECTIVO72 = "IM_EFECT_72";
	private static final String EFECTIVO96 = "IM_EFECT_96";
	private static final String CALCULAR = "NU_CALCULAR";	

	/**
	 * Devuelve un objeto InstrumentosSimulacion , a partir, de un  intrumento type
	 * @param type
	 * 
	 * @param types    type
	 */
	@Override
	public List<InstrumentoType> convert(ResultSet rs){
		List<InstrumentoType> types = new ArrayList<InstrumentoType>();		
		try {
			while (rs.next()) {
				InstrumentoType type = new InstrumentoType();				
				type.setId(rs.getString(ID));
				type.setCdContrato(new BigDecimal(rs.getLong(CDCONTRATO)));
				type.setCdClasificacion(rs.getString(CDCLASIFICACION));
				type.setClasificacion(rs.getString(CLASIFICACION));
				if(rs.getString(TIPOCONTRATO)!=null) type.setTipoContrato(TipoContrato.valueOf(rs.getString(TIPOCONTRATO)));
				type.setCdValorBmv(rs.getString(CDVALORBMV));
				type.setEmisora(rs.getString(EMISORA));
				type.setSerie(rs.getString(SERIE));
				type.setCaTitulos(new BigDecimal(rs.getLong(CATITULOS)));
				type.setCaPrecio(new BigDecimal(rs.getDouble(CAPRECIO)));
				type.setCaMonto(new BigDecimal(rs.getDouble(CAMONTO)));
				type.setCaLiquidez(new BigDecimal(rs.getDouble(CALIQUIDEZ)));
				type.setCaPcIntegracion(new BigDecimal(rs.getDouble(CAPCINTEGRACION)));				
				type.setCaDeltaInstrumento(new BigDecimal(rs.getLong(CADELTAINSTRUMENTO)));
				type.setCaContribucionDelta(new BigDecimal(rs.getLong(CACONTRIBUCIONDELTA)));
				type.setCaTasa(new BigDecimal(rs.getDouble(CATASA)));
				type.setCaValuacionCartera(new BigDecimal(rs.getDouble(CAVALUACIONCARTERA)));
				type.setCaBenchPcIntegracion(new BigDecimal(rs.getDouble(CABENCHPCINTEGRACION)));
				type.setCaBenchContribucionDelta(new BigDecimal(rs.getLong(CABENCHCONTRIBUCIONDELTA)));
				type.setCaDiferenciaPcIntegracion(new BigDecimal(rs.getDouble(CADIFERENCIAPCINTEGRACION)));
				type.setCaSubOSobreDeltas(new BigDecimal(rs.getLong(CASUBOSOBREDELTAS)));
				type.setCfTitulos(new BigDecimal(rs.getLong(CFTITULOS)));
				type.setCfPrecio(new BigDecimal(rs.getDouble(CFPRECIO)));
				type.setCfMonto(new BigDecimal(rs.getDouble(CFMONTO)));
				type.setCfLiquidez(new BigDecimal(rs.getDouble(CFLIQUIDEZ)));
				type.setCfPcIntegracion(new BigDecimal(rs.getDouble(CFPCINTEGRACION)));
				type.setCfDeltaInstrumento(new BigDecimal(rs.getLong(CFDELTAINSTRUMENTO)));
				type.setCfContribucionDelta(new BigDecimal(rs.getLong(CFCONTRIBUCIONDELTA)));
				type.setCfTasa(new BigDecimal(rs.getDouble(CFTASA)));
				type.setCfValuacionCartera(new BigDecimal(rs.getDouble(CFVALUACIONCARTERA)));
				type.setCfBenchPcIntegracion(new BigDecimal(rs.getDouble(CFBENCHPCINTEGRACION)));
				type.setCfBenchContribucionDelta(new BigDecimal(rs.getLong(CFBENCHCONTRIBUCIONDELTA)));
				type.setCfDiferenciaPcIntegracion(new BigDecimal(rs.getDouble(CFDIFERENCIAPCINTEGRACION)));
				type.setCfSubOSobreDeltas(new BigDecimal(rs.getLong(CFSUBOSOBREDELTAS)));
				type.setMontoOperar(new BigDecimal(rs.getDouble(MONTOOPERAR)));
				type.setPcIntegracionObjetivo(new BigDecimal(rs.getDouble(PCINTEGRACIONOBJETIVO)));				
				type.setPcDifIntegracionObjetivo(new BigDecimal(rs.getDouble(PCDIFINTEGRACIONOBJETIVO)));
				type.setValorNominal(new BigDecimal(rs.getDouble(VALORNOMINAL)));
				if(rs.getString(TIPONOMINAL)!=null) type.setTipoNominal(TipoNominal.valueOf(rs.getString(TIPONOMINAL)));
				type.setImpactoMonto(new BigDecimal(rs.getDouble(IMPACTOMONTO)));
				type.setImpactoTitulos(new BigDecimal(rs.getLong(IMPACTOTITULOS)));
				type.setImpactoMontoFideicomisos(new BigDecimal(rs.getDouble(IMPACTOMONTOFIDEICOMISOS)));
				type.setImpactoMontoPatrimonial(new BigDecimal(rs.getDouble(IMPACTOMONTOPATRIMONIAL)));
				type.setImpactoMontoTotal(new BigDecimal(rs.getDouble(IMPACTOMONTOTOTAL)));
				type.setTipoNivel(TipoNivel.valueOf(rs.getString(TIPONIVEL)));
				if(rs.getString(TIPOOPERACION)!=null) type.setTipoOperacion(TipoOperacion.valueOf(rs.getString(TIPOOPERACION)));
				type.setEfectivoHoy(new BigDecimal(rs.getDouble(EFECTIVOHOY)));
				type.setEfectivo24(new BigDecimal(rs.getDouble(EFECTIVO24)));
				type.setEfectivo48(new BigDecimal(rs.getDouble(EFECTIVO48)));
				type.setEfectivo72(new BigDecimal(rs.getDouble(EFECTIVO72)));
				type.setEfectivo96(new BigDecimal(rs.getDouble(EFECTIVO96)));
				type.setCalcular(rs.getInt(CALCULAR));			
				types.add(type);
			}
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return types;
	}

}